import Cookies from 'js-cookie'


/**
 * 设置cookies
 * @param {*} key cookies名称
 * @param {*} value cookies值
 * @param {*} expires 过期时间，单位秒,默认43200秒，即12小时
 */
function setCookies(key,value,expires=432000){
	let time = new Date(new Date() * 1 + expires * 1000);
	//Cookies.set(key, value, { expires: time });
	// sessionStorage和localStorage都缓存，防止app下不兼容或者缓存丢失
	sessionStorage.setItem(key,value)
	//localStorage.setItem(key,value)
}

function getCacheData(key){
	let ck = Cookies.get(key)
	if(ck){
		return ck
	}else if(localStorage.getItem(key)){
		return localStorage.getItem(key)
	}else if(sessionStorage.getItem(key)){
		return sessionStorage.getItem(key)
	}
}
function removeCacheData(key){
	Cookies.remove(key)
	localStorage.removeItem(key)
	sessionStorage.removeItem(key)
}

// 在mian.js中全局引入
export default  {
	get: getCacheData,//Cookies.get(key),
	// set: (key,value) => Cookies.set(key, value),
	set:setCookies,
	remove: removeCacheData
}
